package net.cathackers.devel.scmp.chat.impl.sockets;

import org.apache.log4j.Logger;

import net.cathackers.devel.scmp.chat.interfaces.sockets.SocketServer;
import net.cathackers.devel.scmp.chat.interfaces.sockets.SocketServerMonitor;
import net.cathackers.devel.scmp.factories.SCMPFactory;

public class SocketServerMonitorImpl extends Thread implements
	SocketServerMonitor {
    private SocketServer socketServer_;
    private int pollTime_ = 5;
    private boolean stop_;
    private Logger logger_;

    public SocketServerMonitorImpl(SocketServer socketServer) {
	socketServer_ = socketServer;
	stop_ = false;
	logger_ = SCMPFactory.getLogger(this);
    }

    @Override
    public synchronized void start() {
	super.start();
    }

    @Override
    public void run() {
	// implement monitoring process over the lobby users.
	try {
	    while (!stop_) {
		sleep(pollTime_ * 1000);
		logger_.debug("Doing Regular Scan...");
	    }
	} catch (Exception e) {
	    logger_
		    .error("Socket Server Monitoring Thread has been interrupted:"
			    + e.getMessage());
	}
    }

    @Override
    public int getPollTime() {
	return pollTime_;
    }

    @Override
    public void setPollTime(int seconds) {
	pollTime_ = seconds;
    }

    @Override
    public void stopMonitor() {
	stop_ = true;
    }
}
